<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<script type="text/javascript" src="js/aes.js">
			
		</script>
		<script type="text/javascript" src="js/jquery-1.10.1.js">
			
		</script>
		<title></title>
	</head>
	<body>
		<input type="text" name="put" id="put" value="" />
	</body>
	<script type="text/javascript">
		
		var key1 = CryptoJS.enc.Utf8.parse("8NONwyJtHesysWpM");  
		//这个key是公钥8NONwyJtHesysWpM
  
    var plaintText = 'songpf'; // 明文  
  
    var encryptedData = CryptoJS.AES.encrypt(plaintText, key1, {  
        mode: CryptoJS.mode.ECB,  
        padding: CryptoJS.pad.Pkcs7  
    });  
  
    console.log("加密前："+plaintText);  
    console.log("加密后："+encryptedData);
    //这是加密后的返回的字符串
  
    encryptedData = encryptedData.ciphertext.toString();  
    console.log("转化后："+encryptedData);
    //把这个值作为key对密码进行加密
  
    var encryptedHexStr = CryptoJS.enc.Hex.parse(encryptedData);  
    var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr);  
  //解密
    var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key1, {  
        mode: CryptoJS.mode.ECB,  
        padding: CryptoJS.pad.Pkcs7  
    });  
  
    var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);  
  
    console.log("解密后:"+decryptedStr);  
  
      
     var pwd = "PCsUFtgog9/qpqmqXsuCRQ==";  
    //加密服务端返回的数据  
    var decryptedData = CryptoJS.AES.decrypt(pwd, key, {  
        mode: CryptoJS.mode.ECB,  
        padding: CryptoJS.pad.Pkcs7  
    });  
      
    console.log("解密服务端返回的数据:"+decryptedStr);  
	</script>
</html>
